#include <QtWidgets>
#include <QtNetwork/QLocalSocket>
#include <QTranslator>
#include "mainwindow.h"

#include <QtCore/QList>
#include "zone.h"

int main(int argc, char** argv)
{
  QApplication app(argc, argv);
  qRegisterMetaType<QList<Zone> >("QList<Zone>");

  // Verify if an instance of the programme is already running
  QLocalSocket* sck = new QLocalSocket;
  sck->connectToServer("rift-tool-app-srv", QIODevice::WriteOnly);
  if(sck->waitForConnected(50))
    {
      // The programme is already running
      sck->write("show"); // Ask the main instance to show up
      sck->disconnectFromServer();
      sck->close();
      delete sck;
      return EXIT_SUCCESS;
    }
  delete sck;

  // If not, continue running

  // Install translator
  QTranslator myTranslator;
  if(myTranslator.load("mytr_" + QLocale::system().name()))
    app.installTranslator(&myTranslator);

  // Create programme's window
  app.setQuitOnLastWindowClosed(false);
  MainWindow window;
  if(!app.arguments().contains("silent"))
    window.show();

  return app.exec();
}
